/*
 * @copyright IMTT. Co. Ltd.
 * 
 * Here is detailed comment.
 */
package com.apis.web.goods;

import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.apis.bussiness.entity.IGoods;
import com.apis.bussiness.entity.impl.GoodsImpl;
import com.apis.bussiness.entries.impl.GoodsMgrImpl;
import com.apis.web.Action;
import com.apis.web.XmlResponse;





/**
 * @author LiHongChun
 * @date 2012-10-25
 * @copyright IMTT. Co. Ltd.
 */
public class AddGoods extends Action {

	@Override
	public void execute(HttpServletRequest req, HttpServletResponse resp) {
		// TODO Auto-generated method stub
		XmlResponse xml = new XmlResponse();
		xml.setRequest(Request(req));

		String name = req.getParameter("goods-name");
		String code = req.getParameter("goods-code");
		float price = Float.parseFloat( req.getParameter("goods-price"));
		String desc = req.getParameter("goods-desc");
		String typeId = req.getParameter("type-id");
		
		GoodsMgrImpl goodsMgr = new GoodsMgrImpl();
		IGoods goods = new GoodsImpl();
		goods.setName(name);
		goods.setCode(code);
		goods.setPrice(price);
		goods.setDescription(desc);
		
		try{
			goodsMgr.save(goods);
			xml.setState(1);
		}catch(Exception e){
			String reason = "操作失败.....";
			xml.setReason(reason);	
			xml.setException(e);
		}
		
		Response(resp, xml.toString());		
	}

	@Override
	public int getActionID() {
		// TODO Auto-generated method stub
		return 1001;
	}

}
